<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>主从同步配置 | 美多商城</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../C09-Database/ReadWriteSeparate.html" />
    
    
    <link rel="prev" href="../C09-Database/index.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="9.1"
        data-chapter-title="主从同步配置"
        data-filepath="C09-Database/MasterSlave.md"
        data-basepath=".."
        data-revision="Thu May 24 2018 15:58:46 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        美多商城
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-Prepare/index.html">
            
                
                    <a href="../C01-Prepare/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        项目准备
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-Prepare/BusinessModel.html">
            
                
                    <a href="../C01-Prepare/BusinessModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        商业模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-Prepare/DevelopmentProcess.html">
            
                
                    <a href="../C01-Prepare/DevelopmentProcess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        开发流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-Prepare/ProductAnalysis.html">
            
                
                    <a href="../C01-Prepare/ProductAnalysis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        需求分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="C01-Prepare/ProjectStructure.html">
            
                
                    <a href="../C01-Prepare/ProjectStructure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        项目架构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="C01-Prepare/StartProject.html">
            
                
                    <a href="../C01-Prepare/StartProject.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        创建工程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="C01-Prepare/Config.html">
            
                
                    <a href="../C01-Prepare/Config.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-Users/index.html">
            
                
                    <a href="../C02-Users/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        用户部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-Users/UserModel.html">
            
                
                    <a href="../C02-Users/UserModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        用户模型类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C02-Users/Register.html">
            
                
                    <a href="../C02-Users/Register.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="C02-Users/CORS.html">
            
                
                    <a href="../C02-Users/CORS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        跨域CORS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="C02-Users/JWT.html">
            
                
                    <a href="../C02-Users/JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="C02-Users/DRF-JWT.html">
            
                
                    <a href="../C02-Users/DRF-JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        Django REST framework JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="C02-Users/Login.html">
            
                
                    <a href="../C02-Users/Login.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        登录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="C02-Users/FindPassword/index.html">
            
                
                    <a href="../C02-Users/FindPassword/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        找回密码
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="C02-Users/FindPassword/Step1.html">
            
                
                    <a href="../C02-Users/FindPassword/Step1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.1.</b>
                        
                        第一步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="C02-Users/FindPassword/Step2.html">
            
                
                    <a href="../C02-Users/FindPassword/Step2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.2.</b>
                        
                        第二步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.3" data-path="C02-Users/FindPassword/Step3.html">
            
                
                    <a href="../C02-Users/FindPassword/Step3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.3.</b>
                        
                        第三步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.4" data-path="C02-Users/FindPassword/Step4.html">
            
                
                    <a href="../C02-Users/FindPassword/Step4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.4.</b>
                        
                        第四步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="C02-Users/QQLogin/index.html">
            
                
                    <a href="../C02-Users/QQLogin/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        QQ登录
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.8.1" data-path="C02-Users/QQLogin/Step1.html">
            
                
                    <a href="../C02-Users/QQLogin/Step1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.1.</b>
                        
                        第一步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8.2" data-path="C02-Users/QQLogin/Step2.html">
            
                
                    <a href="../C02-Users/QQLogin/Step2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.2.</b>
                        
                        第二步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8.3" data-path="C02-Users/QQLogin/Step3.html">
            
                
                    <a href="../C02-Users/QQLogin/Step3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.3.</b>
                        
                        第三步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="C02-Users/UserInfo.html">
            
                
                    <a href="../C02-Users/UserInfo.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        用户中心个人信息
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="C02-Users/Email/index.html">
            
                
                    <a href="../C02-Users/Email/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        邮件与验证
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.10.1" data-path="C02-Users/Email/DjangoEmail.html">
            
                
                    <a href="../C02-Users/Email/DjangoEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.1.</b>
                        
                        Django发送邮件的方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10.2" data-path="C02-Users/Email/SendEmail.html">
            
                
                    <a href="../C02-Users/Email/SendEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.2.</b>
                        
                        保存邮箱并发送验证邮件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10.3" data-path="C02-Users/Email/VerifyEmail.html">
            
                
                    <a href="../C02-Users/Email/VerifyEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.3.</b>
                        
                        验证邮箱链接
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="C02-Users/Address/index.html">
            
                
                    <a href="../C02-Users/Address/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        收货地址
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.11.1" data-path="C02-Users/Address/AreaSelect.html">
            
                
                    <a href="../C02-Users/Address/AreaSelect.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.1.</b>
                        
                        省市区地址查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11.2" data-path="C02-Users/Address/Cache.html">
            
                
                    <a href="../C02-Users/Address/Cache.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.2.</b>
                        
                        使用缓存
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11.3" data-path="C02-Users/Address/UserAddressManagement.html">
            
                
                    <a href="../C02-Users/Address/UserAddressManagement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.3.</b>
                        
                        用户地址管理
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Goods/index.html">
            
                
                    <a href="../C03-Goods/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        商品部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Goods/DatabaseDesign.html">
            
                
                    <a href="../C03-Goods/DatabaseDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        数据表设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Goods/FastDFS.html">
            
                
                    <a href="../C03-Goods/FastDFS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        FastDFS分布式文件系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Goods/Docker/index.html">
            
                
                    <a href="../C03-Goods/Docker/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Docker使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="C03-Goods/Docker/Introduce.html">
            
                
                    <a href="../C03-Goods/Docker/Introduce.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        Docker简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="C03-Goods/Docker/InstallAndOperations.html">
            
                
                    <a href="../C03-Goods/Docker/InstallAndOperations.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        安装与操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Goods/FastDFSDocker.html">
            
                
                    <a href="../C03-Goods/FastDFSDocker.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        使用Docker安装FastDFS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="C03-Goods/FastDFSClientAndDjangoFileSystem.html">
            
                
                    <a href="../C03-Goods/FastDFSClientAndDjangoFileSystem.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        FastDFS客户端与自定义文件存储系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="C03-Goods/CKEditor.html">
            
                
                    <a href="../C03-Goods/CKEditor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        CKEditor富文本编辑器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="C03-Goods/ImportGoodsData.html">
            
                
                    <a href="../C03-Goods/ImportGoodsData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        添加测试数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="C03-Goods/FreezeHTML.html">
            
                
                    <a href="../C03-Goods/FreezeHTML.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        页面静态化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="C03-Goods/DjangoCrontab.html">
            
                
                    <a href="../C03-Goods/DjangoCrontab.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        定时任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="C03-Goods/GenerateIndexHTMLScript.html">
            
                
                    <a href="../C03-Goods/GenerateIndexHTMLScript.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        静态化首页的手动脚本
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="C03-Goods/GoodsDetail.html">
            
                
                    <a href="../C03-Goods/GoodsDetail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.11.</b>
                        
                        商品详情页面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="C03-Goods/HotSaleGoods.html">
            
                
                    <a href="../C03-Goods/HotSaleGoods.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.12.</b>
                        
                        热销商品
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="C03-Goods/UserBrowseHistory.html">
            
                
                    <a href="../C03-Goods/UserBrowseHistory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.13.</b>
                        
                        用户浏览历史记录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.14" data-path="C03-Goods/GoodsList.html">
            
                
                    <a href="../C03-Goods/GoodsList.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.14.</b>
                        
                        商品列表页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.15" data-path="C03-Goods/GoodsSearch.html">
            
                
                    <a href="../C03-Goods/GoodsSearch.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.15.</b>
                        
                        商品搜索
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-Cart/index.html">
            
                
                    <a href="../C04-Cart/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        购物车部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C04-Cart/DataStructureDesign.html">
            
                
                    <a href="../C04-Cart/DataStructureDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        购物车数据存储设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C04-Cart/Implement.html">
            
                
                    <a href="../C04-Cart/Implement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        购物车实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-Cart/MergeCart.html">
            
                
                    <a href="../C04-Cart/MergeCart.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        登录合并购物车
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-Order/index.html">
            
                
                    <a href="../C05-Order/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        订单部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-Order/OrderDBModel.html">
            
                
                    <a href="../C05-Order/OrderDBModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        订单数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-Order/PlaceOrder.html">
            
                
                    <a href="../C05-Order/PlaceOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        订单结算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="C05-Order/SaveOrder.html">
            
                
                    <a href="../C05-Order/SaveOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        保存订单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="C05-Order/OrderSuccess.html">
            
                
                    <a href="../C05-Order/OrderSuccess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        下单成功
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="C06-Pay/index.html">
            
                
                    <a href="../C06-Pay/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        支付宝支付
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="C06-Pay/Alipay.html">
            
                
                    <a href="../C06-Pay/Alipay.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        接入支付宝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="C06-Pay/Paying.html">
            
                
                    <a href="../C06-Pay/Paying.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        发起支付
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="C06-Pay/PaymentResult.html">
            
                
                    <a href="../C06-Pay/PaymentResult.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        保存支付结果
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="C07-Xadmin.html">
            
                
                    <a href="../C07-Xadmin.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        Xadmin
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="C08-Permission.html">
            
                
                    <a href="../C08-Permission.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        用户权限控制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="C09-Database/index.html">
            
                
                    <a href="../C09-Database/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        数据库读写分离
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="9.1" data-path="C09-Database/MasterSlave.html">
            
                
                    <a href="../C09-Database/MasterSlave.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        主从同步配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="C09-Database/ReadWriteSeparate.html">
            
                
                    <a href="../C09-Database/ReadWriteSeparate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        Django数据库读写分离
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="C10-Deploy.html">
            
                
                    <a href="../C10-Deploy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        Django部署
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >美多商城</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="mysql&#x4E3B;&#x4ECE;&#x540C;&#x6B65;">MySQL&#x4E3B;&#x4ECE;&#x540C;&#x6B65;</h1>
<h2 id="1----&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x7684;&#x5B9A;&#x4E49;">1.    &#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x7684;&#x5B9A;&#x4E49;</h2>
<p>&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x4F7F;&#x5F97;&#x6570;&#x636E;&#x53EF;&#x4EE5;&#x4ECE;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x670D;&#x52A1;&#x5668;&#x590D;&#x5236;&#x5230;&#x5176;&#x4ED6;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#xFF0C;&#x5728;&#x590D;&#x5236;&#x6570;&#x636E;&#x65F6;&#xFF0C;&#x4E00;&#x4E2A;&#x670D;&#x52A1;&#x5668;&#x5145;&#x5F53;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#xFF08;master&#xFF09;&#xFF0C;&#x5176;&#x4F59;&#x7684;&#x670D;&#x52A1;&#x5668;&#x5145;&#x5F53;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#xFF08;slave&#xFF09;&#x3002;&#x56E0;&#x4E3A;&#x590D;&#x5236;&#x662F;&#x5F02;&#x6B65;&#x8FDB;&#x884C;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x4E0D;&#x9700;&#x8981;&#x4E00;&#x76F4;&#x8FDE;&#x63A5;&#x7740;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x751A;&#x81F3;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x62E8;&#x53F7;&#x65AD;&#x65AD;&#x7EED;&#x7EED;&#x5730;&#x8FDE;&#x63A5;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x3002;&#x901A;&#x8FC7;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x590D;&#x5236;&#x6240;&#x6709;&#x7684;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x67D0;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x751A;&#x81F3;&#x662F;&#x67D0;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x4E0A;&#x7684;&#x67D0;&#x4E2A;&#x8868;&#x3002; </p>
<p><strong>&#x4F7F;&#x7528;&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x7684;&#x597D;&#x5904;&#xFF1A;</strong></p>
<p>&#xFF08;1&#xFF09;  &#x901A;&#x8FC7;&#x589E;&#x52A0;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x6765;<strong>&#x63D0;&#x9AD8;&#x6570;&#x636E;&#x5E93;&#x7684;&#x6027;&#x80FD;</strong>&#xFF0C;&#x5728;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x6267;&#x884C;&#x5199;&#x5165;&#x548C;&#x66F4;&#x65B0;&#xFF0C;&#x5728;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x5411;&#x5916;&#x63D0;&#x4F9B;&#x8BFB;&#x529F;&#x80FD;&#xFF0C;&#x53EF;&#x4EE5;&#x52A8;&#x6001;&#x5730;&#x8C03;&#x6574;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x7684;&#x6570;&#x91CF;&#xFF0C;&#x4ECE;&#x800C;&#x8C03;&#x6574;&#x6574;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x7684;&#x6027;&#x80FD;&#x3002;</p>
<p>&#xFF08;2&#xFF09;  <strong>&#x63D0;&#x9AD8;&#x6570;&#x636E;&#x5B89;&#x5168;</strong>&#xFF0C;&#x56E0;&#x4E3A;&#x6570;&#x636E;&#x5DF2;&#x590D;&#x5236;&#x5230;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x53EF;&#x4EE5;&#x7EC8;&#x6B62;&#x590D;&#x5236;&#x8FDB;&#x7A0B;&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x5907;&#x4EFD;&#x800C;&#x4E0D;&#x7834;&#x574F;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x76F8;&#x5E94;&#x6570;&#x636E;</p>
<p>&#xFF08;3&#xFF09;  &#x5728;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x751F;&#x6210;&#x5B9E;&#x65F6;&#x6570;&#x636E;&#xFF0C;&#x800C;&#x5728;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x5206;&#x6790;&#x8FD9;&#x4E9B;&#x6570;&#x636E;&#xFF0C;&#x4ECE;&#x800C;<strong>&#x63D0;&#x9AD8;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x7684;&#x6027;&#x80FD;</strong></p>
<h2 id="2----&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x7684;&#x673A;&#x5236;">2.    &#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x7684;&#x673A;&#x5236;</h2>
<p>Mysql&#x670D;&#x52A1;&#x5668;&#x4E4B;&#x95F4;&#x7684;&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x662F;&#x57FA;&#x4E8E;&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#x673A;&#x5236;&#xFF0C;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x4F7F;&#x7528;&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#x6765;&#x8BB0;&#x5F55;&#x6570;&#x636E;&#x5E93;&#x7684;&#x53D8;&#x52A8;&#x60C5;&#x51B5;&#xFF0C;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x901A;&#x8FC7;&#x8BFB;&#x53D6;&#x548C;&#x6267;&#x884C;&#x8BE5;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x6765;&#x4FDD;&#x6301;&#x548C;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x7684;&#x6570;&#x636E;&#x4E00;&#x81F4;&#x3002; </p>
<p>&#x5728;&#x4F7F;&#x7528;&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#x65F6;&#xFF0C;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x7684;&#x6240;&#x6709;&#x64CD;&#x4F5C;&#x90FD;&#x4F1A;&#x88AB;&#x8BB0;&#x5F55;&#x4E0B;&#x6765;&#xFF0C;&#x7136;&#x540E;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x4F1A;&#x63A5;&#x6536;&#x5230;&#x8BE5;&#x65E5;&#x5FD7;&#x7684;&#x4E00;&#x4E2A;&#x526F;&#x672C;&#x3002;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x6267;&#x884C;&#x8BE5;&#x65E5;&#x5FD7;&#x4E2D;&#x7684;&#x54EA;&#x4E00;&#x7C7B;&#x4E8B;&#x4EF6;&#xFF08;&#x8B6C;&#x5982;&#x53EA;&#x63D2;&#x5165;&#x6570;&#x636E;&#x6216;&#x8005;&#x53EA;&#x66F4;&#x65B0;&#x6570;&#x636E;&#xFF09;&#xFF0C;&#x9ED8;&#x8BA4;&#x4F1A;&#x6267;&#x884C;&#x65E5;&#x5FD7;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x8BED;&#x53E5;&#x3002;</p>
<p>&#x6BCF;&#x4E00;&#x4E2A;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x4F1A;&#x8BB0;&#x5F55;&#x5173;&#x4E8E;&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#x7684;&#x4FE1;&#x606F;&#xFF1A;&#x6587;&#x4EF6;&#x540D;&#x548C;&#x5DF2;&#x7ECF;&#x5904;&#x7406;&#x8FC7;&#x7684;&#x8BED;&#x53E5;&#xFF0C;&#x8FD9;&#x6837;&#x610F;&#x5473;&#x7740;&#x4E0D;&#x540C;&#x7684;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x53EF;&#x4EE5;&#x5206;&#x522B;&#x6267;&#x884C;&#x540C;&#x4E00;&#x4E2A;&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#x7684;&#x4E0D;&#x540C;&#x90E8;&#x5206;&#xFF0C;&#x5E76;&#x4E14;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x53EF;&#x4EE5;&#x968F;&#x65F6;&#x8FDE;&#x63A5;&#x6216;&#x8005;&#x4E2D;&#x65AD;&#x548C;&#x670D;&#x52A1;&#x5668;&#x7684;&#x8FDE;&#x63A5;&#x3002;</p>
<p> &#x4E3B;&#x670D;&#x52A1;&#x5668;&#x548C;&#x6BCF;&#x4E00;&#x4E2A;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x90FD;&#x5FC5;&#x987B;&#x914D;&#x7F6E;&#x4E00;&#x4E2A;&#x552F;&#x4E00;&#x7684;ID&#x53F7;&#xFF08;&#x5728;my.cnf&#x6587;&#x4EF6;&#x7684;[mysqld]&#x6A21;&#x5757;&#x4E0B;&#x6709;&#x4E00;&#x4E2A;server-id&#x914D;&#x7F6E;&#x9879;&#xFF09;&#xFF0C;&#x53E6;&#x5916;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x8FD8;&#x9700;&#x8981;&#x901A;&#x8FC7;CHANGE MASTER TO&#x8BED;&#x53E5;&#x6765;&#x914D;&#x7F6E;&#x5B83;&#x8981;&#x8FDE;&#x63A5;&#x7684;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x7684;ip&#x5730;&#x5740;&#xFF0C;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x540D;&#x79F0;&#x548C;&#x8BE5;&#x65E5;&#x5FD7;&#x91CC;&#x9762;&#x7684;&#x4F4D;&#x7F6E;&#xFF08;&#x8FD9;&#x4E9B;&#x4FE1;&#x606F;&#x5B58;&#x50A8;&#x5728;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x7684;&#x6570;&#x636E;&#x5E93;&#x91CC;&#xFF09;</p>
<h2 id="3----&#x914D;&#x7F6E;&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x7684;&#x57FA;&#x672C;&#x6B65;&#x9AA4;">3.    &#x914D;&#x7F6E;&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x7684;&#x57FA;&#x672C;&#x6B65;&#x9AA4;</h2>
<p>&#x6709;&#x5F88;&#x591A;&#x79CD;&#x914D;&#x7F6E;&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x603B;&#x7ED3;&#x4E3A;&#x5982;&#x4E0B;&#x7684;&#x6B65;&#x9AA4;&#xFF1A;</p>
<p>&#xFF08;1&#xFF09;  &#x5728;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#xFF0C;&#x5FC5;&#x987B;&#x5F00;&#x542F;&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#x673A;&#x5236;&#x548C;&#x914D;&#x7F6E;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;ID</p>
<p>&#xFF08;2&#xFF09;  &#x5728;&#x6BCF;&#x4E00;&#x4E2A;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#xFF0C;&#x914D;&#x7F6E;&#x4E00;&#x4E2A;&#x552F;&#x4E00;&#x7684;ID&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7528;&#x6765;&#x4E13;&#x95E8;&#x590D;&#x5236;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x6570;&#x636E;&#x7684;&#x8D26;&#x53F7;</p>
<p>&#xFF08;3&#xFF09;  &#x5728;&#x5F00;&#x59CB;&#x590D;&#x5236;&#x8FDB;&#x7A0B;&#x524D;&#xFF0C;&#x5728;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x8BB0;&#x5F55;&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;&#x7684;&#x4F4D;&#x7F6E;&#x4FE1;&#x606F;</p>
<p>&#xFF08;4&#xFF09;  &#x5982;&#x679C;&#x5728;&#x5F00;&#x59CB;&#x590D;&#x5236;&#x4E4B;&#x524D;&#xFF0C;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x5DF2;&#x7ECF;&#x6709;&#x6570;&#x636E;&#xFF0C;&#x5C31;&#x5FC5;&#x987B;&#x5148;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x5FEB;&#x7167;&#xFF08;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;mysqldump&#x5BFC;&#x51FA;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x6216;&#x8005;&#x76F4;&#x63A5;&#x590D;&#x5236;&#x6570;&#x636E;&#x6587;&#x4EF6;&#xFF09;</p>
<p>&#xFF08;5&#xFF09;  &#x914D;&#x7F6E;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x8981;&#x8FDE;&#x63A5;&#x7684;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x7684;IP&#x5730;&#x5740;&#x548C;&#x767B;&#x9646;&#x6388;&#x6743;&#xFF0C;&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x540D;&#x548C;&#x4F4D;&#x7F6E;</p>
<h2 id="4--&#x8BE6;&#x7EC6;&#x914D;&#x7F6E;&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x7684;&#x65B9;&#x6CD5;">4.  &#x8BE6;&#x7EC6;&#x914D;&#x7F6E;&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x7684;&#x65B9;&#x6CD5;</h2>
<h4 id="1&#xFF09;&#x5B89;&#x88C5;mysql">1&#xFF09;&#x5B89;&#x88C5;mysql</h4>
<p>&#x6211;&#x4EEC;&#x5728;ubuntu&#x4E2D;&#x5DF2;&#x7ECF;&#x6709;&#x5B89;&#x88C5;&#x4E00;&#x53F0;mysql&#x4E86;&#xFF0C;&#x73B0;&#x5728;&#x4F7F;&#x7528;docker&#x5B89;&#x88C5;&#x53E6;&#x5916;&#x4E00;&#x53F0;mysql</p>
<p>&#x83B7;&#x53D6;mysql&#x7684;&#x955C;&#x50CF;&#xFF0C;&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x5C3D;&#x91CF;&#x4FDD;&#x8BC1;&#x591A;&#x53F0;mysql&#x7684;&#x7248;&#x672C;&#x76F8;&#x540C;&#xFF0C;&#x6211;&#x4EEC;&#x7684;ubuntu&#x4E2D;&#x5B58;&#x5728;&#x7684;mysql&#x662F;5.7.22&#x7248;&#x672C;&#xFF0C;&#x6240;&#x4EE5;&#x83B7;&#x53D6;5.7.22&#x7248;&#x672C;&#x7684;&#x955C;&#x50CF;</p>
<pre><code class="lang-shell">docker image pull mysql:5.7.22
&#x6216;
docker load -i mysql_docker_5722.tar
</code></pre>
<p>&#x8FD0;&#x884C;mysql docker&#x955C;&#x50CF;&#xFF0C;&#x9700;&#x8981;&#x5728;&#x5BBF;&#x4E3B;&#x673A;&#x4E2D;&#x5EFA;&#x7ACB;&#x6587;&#x4EF6;&#x76EE;&#x5F55;&#x7528;&#x4E8E;mysql&#x5BB9;&#x5668;&#x4FDD;&#x5B58;&#x6570;&#x636E;&#x548C;&#x8BFB;&#x53D6;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x5728;&#x5BB6;&#x76EE;&#x5F55;&#x4E2D;&#xFF08;/home/python&#xFF09;&#x4E2D;&#x521B;&#x5EFA;&#x76EE;&#x5F55;&#xFF0C;&#x5C06;mysql&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x653E;&#x5230;&#x6B64;&#x76EE;&#x5F55;&#x4E2D;</p>
<pre><code class="lang-shell">cd ~
mkdir mysql_slave
cd mysql_slave
mkdir data
cp /etc/mysql/mysql.conf.d ./
</code></pre>
<p>&#x6211;&#x4EEC;&#x8981;&#x5C06;docker&#x8FD0;&#x884C;&#x7684;mysql&#x4F5C;&#x4E3A;slave&#x6765;&#x8FD0;&#x884C;&#xFF0C;&#x5F00;&#x542F;&#x524D;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x7F16;&#x8F91; ~/mysql_slave/mysql.conf.d/mysqld.cnf &#x6587;&#x4EF6;&#xFF0C;&#x4FEE;&#x6539;</p>
<pre><code class="lang-shell">port  =  8306
general_log  = 0
server-id  = 2
</code></pre>
<p><strong>&#x6211;&#x4EEC;&#x8BA9;&#x6B64;&#x53F0;mysql&#x8FD0;&#x884C;&#x5728;8306&#x7AEF;&#x53E3;&#x4E0A;</strong>&#xFF0C;&#x4E14;mysql&#x7F16;&#x53F7;&#x4E3A;2</p>
<p>&#x521B;&#x5EFA;docker&#x5BB9;&#x5668;</p>
<pre><code class="lang-shell">docker run --name mysql-slave -e MYSQL_ROOT_PASSWORD=mysql -d --network=host -v /home/python/mysql_slave/data:/var/lib/mysql -v /home/python/mysql_slave/mysql.conf.d:/etc/mysql/mysql.conf.d  mysql:5.7.22
</code></pre>
<ul>
<li>MYSQL_ROOT_PASSWORD  &#x662F;&#x521B;&#x5EFA;mysql root&#x7528;&#x6237;&#x7684;&#x5BC6;&#x7801;</li>
</ul>
<p>&#x6D4B;&#x8BD5;&#xFF0C;&#x5728;ubuntu&#x4E2D;&#x4F7F;&#x7528;mysql&#x547D;&#x4EE4;&#x5C1D;&#x8BD5;&#x8FDE;&#x63A5;docker&#x5BB9;&#x5668;&#x4E2D;&#x7684;mysql</p>
<pre><code class="lang-shell">mysql -uroot -pmysql -h 127.0.0.1 --port=8306
</code></pre>
<h4 id="2&#xFF09;&#x5907;&#x4EFD;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x539F;&#x6709;&#x6570;&#x636E;&#x5230;&#x4ECE;&#x670D;&#x52A1;&#x5668;">2&#xFF09;&#x5907;&#x4EFD;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x539F;&#x6709;&#x6570;&#x636E;&#x5230;&#x4ECE;&#x670D;&#x52A1;&#x5668;</h4>
<p>&#x5982;&#x679C;&#x5728;&#x8BBE;&#x7F6E;&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x524D;&#xFF0C;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x5DF2;&#x6709;&#x5927;&#x91CF;&#x6570;&#x636E;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;mysqldump&#x8FDB;&#x884C;&#x6570;&#x636E;&#x5907;&#x4EFD;&#x5E76;&#x8FD8;&#x539F;&#x5230;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x4EE5;&#x5B9E;&#x73B0;&#x6570;&#x636E;&#x7684;&#x590D;&#x5236;&#x3002; </p>
<p>&#x5728;&#x4E3B;&#x670D;&#x52A1;&#x5668;Ubuntu&#x4E0A;&#x8FDB;&#x884C;&#x5907;&#x4EFD;&#xFF0C;&#x6267;&#x884C;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre><code class="lang-shell">mysqldump -uroot -pmysql --all-databases --lock-all-tables &gt; ~/master_db.sql
</code></pre>
<p><img src="../images/mysqldump.png" alt="mysqldump"></p>
<ul>
<li><p>-u &#xFF1A;&#x7528;&#x6237;&#x540D;</p>
</li>
<li><p>-p &#xFF1A;&#x793A;&#x5BC6;&#x7801;</p>
</li>
<li><p>--all-databases &#xFF1A;&#x5BFC;&#x51FA;&#x6240;&#x6709;&#x6570;&#x636E;&#x5E93;</p>
</li>
<li><p>--lock-all-tables &#xFF1A;&#x6267;&#x884C;&#x64CD;&#x4F5C;&#x65F6;&#x9501;&#x4F4F;&#x6240;&#x6709;&#x8868;&#xFF0C;&#x9632;&#x6B62;&#x64CD;&#x4F5C;&#x65F6;&#x6709;&#x6570;&#x636E;&#x4FEE;&#x6539;</p>
</li>
<li><p>~/master_db.sql :&#x5BFC;&#x51FA;&#x7684;&#x5907;&#x4EFD;&#x6570;&#x636E;&#xFF08;sql&#x6587;&#x4EF6;&#xFF09;&#x4F4D;&#x7F6E;&#xFF0C;&#x53EF;&#x81EA;&#x5DF1;&#x6307;&#x5B9A;</p>
</li>
</ul>
<p>&#x5728;docker&#x5BB9;&#x5668;&#x4E2D;&#x5BFC;&#x5165;&#x6570;&#x636E;</p>
<pre><code class="lang-shell">mysql -uroot -pmysql -h127.0.0.1 --port=8306 &lt; ~/master_db.sql
</code></pre>
<h4 id="3&#xFF09;&#x914D;&#x7F6E;&#x4E3B;&#x670D;&#x52A1;&#x5668;master&#xFF08;ubuntu&#x4E2D;&#x7684;mysql&#xFF09;">3&#xFF09;&#x914D;&#x7F6E;&#x4E3B;&#x670D;&#x52A1;&#x5668;master&#xFF08;Ubuntu&#x4E2D;&#x7684;MySQL&#xFF09;</h4>
<p>&#x7F16;&#x8F91;&#x8BBE;&#x7F6E;mysqld&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x8BBE;&#x7F6E;log_bin&#x548C;server-id</p>
<pre><code class="lang-shell">sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
</code></pre>
<p> <img src="../images/master_mysql.png" alt="master_mysql"></p>
<p>&#x91CD;&#x542F;mysql&#x670D;&#x52A1;</p>
<pre><code class="lang-shell">sudo service mysql restart
</code></pre>
<p>&#x767B;&#x5165;&#x4E3B;&#x670D;&#x52A1;&#x5668;Ubuntu&#x4E2D;&#x7684;mysql&#xFF0C;&#x521B;&#x5EFA;&#x7528;&#x4E8E;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x540C;&#x6B65;&#x6570;&#x636E;&#x4F7F;&#x7528;&#x7684;&#x5E10;&#x53F7; </p>
<pre><code class="lang-shell">mysql &#x2013;uroot &#x2013;pmysql

GRANT REPLICATION SLAVE ON *.* TO &apos;slave&apos;@&apos;%&apos; identified by &apos;slave&apos;;

FLUSH PRIVILEGES;
</code></pre>
<p><img src="../images/&#x521B;&#x5EFA;slave&#x8D26;&#x53F7;.png" alt="&#x521B;&#x5EFA;slave&#x8D26;&#x53F7;"></p>
<p>&#x83B7;&#x53D6;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#x4FE1;&#x606F; </p>
<pre><code class="lang-sql"><span class="hljs-operator"><span class="hljs-keyword">SHOW</span> <span class="hljs-keyword">MASTER</span> <span class="hljs-keyword">STATUS</span>;</span>
</code></pre>
<p><img src="../images/&#x83B7;&#x53D6;master&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;.png" alt="&#x83B7;&#x53D6;master&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;"></p>
<p><strong>File&#x4E3A;&#x4F7F;&#x7528;&#x7684;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x540D;&#x5B57;&#xFF0C;Position&#x4E3A;&#x4F7F;&#x7528;&#x7684;&#x6587;&#x4EF6;&#x4F4D;&#x7F6E;&#xFF0C;&#x8FD9;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x987B;&#x8BB0;&#x4E0B;&#xFF0C;&#x914D;&#x7F6E;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x65F6;&#x4F1A;&#x7528;&#x5230;&#x3002;</strong> </p>
<h4 id="4&#xFF09;&#x914D;&#x7F6E;&#x4ECE;&#x670D;&#x52A1;&#x5668;slave-&#xFF08;docker&#x4E2D;&#x7684;mysql&#xFF09;">4&#xFF09;&#x914D;&#x7F6E;&#x4ECE;&#x670D;&#x52A1;&#x5668;slave &#xFF08;docker&#x4E2D;&#x7684;mysql&#xFF09;</h4>
<p>&#x8FDB;&#x5165;docker&#x4E2D;&#x7684;mysql</p>
<pre><code class="lang-shell">mysql -uroot -pmysql -h 127.0.0.1 --port=8306
</code></pre>
<p>&#x6267;&#x884C;</p>
<pre><code class="lang-sql"><span class="hljs-operator"><span class="hljs-keyword">change</span> <span class="hljs-keyword">master</span> <span class="hljs-keyword">to</span> master_host=<span class="hljs-string">&apos;127.0.0.1&apos;</span>, master_user=<span class="hljs-string">&apos;slave&apos;</span>, master_password=<span class="hljs-string">&apos;slave&apos;</span>,master_log_file=<span class="hljs-string">&apos;mysql-bin.000006&apos;</span>, master_log_pos=<span class="hljs-number">590</span>;</span>
</code></pre>
<ul>
<li>master_host&#xFF1A;&#x4E3B;&#x670D;&#x52A1;&#x5668;Ubuntu&#x7684;ip&#x5730;&#x5740;</li>
<li>master_log_file: &#x524D;&#x9762;&#x67E5;&#x8BE2;&#x5230;&#x7684;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x540D;</li>
<li>master_log_pos: &#x524D;&#x9762;&#x67E5;&#x8BE2;&#x5230;&#x7684;&#x4E3B;&#x670D;&#x52A1;&#x5668;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x4F4D;&#x7F6E;</li>
</ul>
<p>&#x542F;&#x52A8;slave&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x5E76;&#x67E5;&#x770B;&#x540C;&#x6B65;&#x72B6;&#x6001;</p>
<pre><code class="lang-sql"><span class="hljs-operator"><span class="hljs-keyword">start</span> <span class="hljs-keyword">slave</span>;</span>
<span class="hljs-operator"><span class="hljs-keyword">show</span> <span class="hljs-keyword">slave</span> <span class="hljs-keyword">status</span> \<span class="hljs-keyword">G</span>
</span></code></pre>
<p><img src="../images/slave&#x72B6;&#x6001;.png" alt="slave&#x72B6;&#x6001;"></p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../C09-Database/index.html" class="navigation navigation-prev " aria-label="Previous page: 数据库读写分离"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../C09-Database/ReadWriteSeparate.html" class="navigation navigation-next " aria-label="Next page: Django数据库读写分离"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
